package com.x_memteor.base_master.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.x_memteor.base_master.bean.request.MeasureBody;
import com.x_memteor.base_master.bean.request.NewHeartBody;
import com.x_memteor.base_master.bean.type_adapter.MeasureTypeAdapter;
import com.x_memteor.base_master.bean.type_adapter.NewHeartTypeAdapter;
import com.x_memteor.base_master.bean.type_adapter.TokenTypeAdapter;
import com.x_memteor.base_master.bean.request.TokenBody;

/**
 * @author: X_Meteor
 * @description: 类描述
 * @version: V_1.0.0
 * @date: 2018/3/12 0012 下午 9:21
 * @company:
 * @email: lx802315@163.com
 */
public class GsonUtils {

    private static GsonUtils mGsonUtils = null;
    private static Gson gson;

    private GsonUtils() {
        createGson();
    }

    public static Gson getInstance() {
        synchronized (GsonUtils.class) {
            if (gson == null) {
                mGsonUtils = new GsonUtils();
            }
        }
        return gson;
    }

    public static Gson createGson() {
        gson = new GsonBuilder()
                .registerTypeAdapter(TokenBody.class, new TokenTypeAdapter())
                .registerTypeAdapter(NewHeartBody.class,new NewHeartTypeAdapter())
                .registerTypeAdapter(MeasureBody.class,new MeasureTypeAdapter())
                .create();
        return gson;
    }
}
